package com.cqs.leetcode.math;

public class ValidPerfectSquare347 {
    public boolean isPerfectSquare(int num) {
        return isPerfectSquare(1,num,num);
    }

    public boolean isPerfectSquare(int left, int right, int num){
        if (left > right) return false;
        int mid = left + (right-left)/2;
        int r = num / mid;
        if (r == mid && (num % mid == 0) ) return true;
        if (r > mid) return isPerfectSquare(mid + 1,right, num);
        return isPerfectSquare(left, mid-1,num);
    }

    public static void main(String[] args) {
        ValidPerfectSquare347 validPerfectSquare347 = new ValidPerfectSquare347();
        System.out.println(Integer.MAX_VALUE);
        for (int i = 1; i <= Integer.MAX_VALUE && i > 0; i++) {
            boolean perfectSquare = validPerfectSquare347.isPerfectSquare(i);
            if (perfectSquare){
                System.out.println(i);
            }
//            System.out.println(i);
        }
    }
}
